﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Threading;
using System.IO;

namespace PayRoller.Code
{
    public class TimerJob
    {
        private Timer singleTimer;
        private int timeInterval;
        private static TimerJob currentJob;

        private TimerJob()
        {
            timeInterval = 60000 * 3;
        }

        public static TimerJob Instance
        {
            get
            {
                currentJob = new TimerJob();
                return currentJob;
            }
        }

        public void Start()
        {
            singleTimer = new Timer(new TimerCallback(call_back), null, timeInterval, timeInterval);
        }


        private void call_back(object state)
        {
            this.SaveExcuteInfoIntoFile();
            singleTimer.Change(timeInterval, timeInterval);
        }

        private void SaveExcuteInfoIntoFile()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "taskLog.txt";
            using (FileStream fileStream = File.Open(filePath, FileMode.OpenOrCreate))
            {
                using (StreamWriter writer = new StreamWriter(fileStream))
                {
                    writer.WriteLine(DateTime.Now.ToString());
                    writer.Close();
                }
                fileStream.Close();
            }
        }
    }
}
